﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO.IsolatedStorage;
using System.Xml.Serialization;
using System.IO;

namespace PhysicsSimulator
{
    public class GameData
    {
        private const string filename = "physicssimulator.xml";

        public GameData()
        {
            //int defaul value

        }

        public void SaveData()
        {
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            IsolatedStorageFileStream stream = storage.CreateFile(filename);
            XmlSerializer xml = new XmlSerializer(GetType());
            xml.Serialize(stream, this);
            stream.Close();
            stream.Dispose();
        }

        public static GameData Load()
        {
            GameData data;
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication();
            if (storage.FileExists(filename))
            {
                FileStream stream = storage.OpenFile(filename, FileMode.Open);
                XmlSerializer xml = new XmlSerializer(typeof(GameData));

                data = xml.Deserialize(stream) as GameData;

                stream.Close();
                stream.Dispose();
            }
            else
            {
                return new GameData();
            }
            return data;
        }
    }
}
